package pv.dao;

import pv.dao.table.CategoryTable;
import pv.dao.table.CountryTable;
import pv.dao.table.DistrictTable;
import pv.dao.table.PlaceTable;
import pv.dao.table.ProvinceTable;
import pv.dao.table.SubCategoryTable;
import pv.dao.table.WardTable;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class SQLiteHelper extends SQLiteOpenHelper {
	public static final int DATABASE_VERSION = 1;
	public static final String DATABASE_NAME = "finderDB.db";

	public SQLiteHelper(Context context) {
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		db.execSQL(CategoryTable.SQL_CREATE_ENTRIES);
		db.execSQL(SubCategoryTable.SQL_CREATE_ENTRIES);
		db.execSQL(WardTable.SQL_CREATE_ENTRIES);
		db.execSQL(ProvinceTable.SQL_CREATE_ENTRIES);
		db.execSQL(DistrictTable.SQL_CREATE_ENTRIES);
		db.execSQL(CountryTable.SQL_CREATE_ENTRIES);
		db.execSQL(PlaceTable.SQL_CREATE_ENTRIES);

	}

	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// This database is only a cache for online data, so its upgrade policy
		// is
		// to simply to discard the data and start over
		db.execSQL(PlaceTable.SQL_DELETE_ENTRIES);
		db.execSQL(CategoryTable.SQL_DELETE_ENTRIES);
		db.execSQL(SubCategoryTable.SQL_DELETE_ENTRIES);
		db.execSQL(WardTable.SQL_DELETE_ENTRIES);
		db.execSQL(ProvinceTable.SQL_DELETE_ENTRIES);
		db.execSQL(DistrictTable.SQL_DELETE_ENTRIES);
		db.execSQL(CountryTable.SQL_DELETE_ENTRIES);
		onCreate(db);
	}

	@Override
	public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		onUpgrade(db, oldVersion, newVersion);

	}

}
